<?php 

/**
  datetime：2016-11-9 19:43 @auth YWH
 */


namespace Admin\Controller;

use Think\Controller;

header("Content-type:text/html;charset=utf-8");

class FirstController extends Controller{


      public function index(){

        // $ip = "211.161.196.174";
        // // $ip = I('server.REMOTE_ADDR');//从server中获取IP

/**
 IP地址接口
 */
        // // //实例化 接口  
        $api = new \Common\Util\ResultApi();
        // // //返回数据
        // $data = $api->getApiData('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip, 'json');

        // if ($data->code != 0) {
        //     echo "IP error !";
        //     return;
        // }

/**
 天气接口
 */
/**和风天气
设置APPkey
  */ 
        $key                = 'e783019393df4ba894f16638129ad7c5';

/**
设置地址
*/  
        $keywords           = "上海";

        $url1               ="https://free-api.heweather.com/v5/search?city=".$keywords."&&key=".$key;

/**
 调用function里的方法 查询天气
 */
        $cityQuery          = curl_https($url1);


        $query              = json_decode($cityQuery);

        $city               = ($query->HeWeather5)[0]->basic->id;



        $url                ="https://free-api.heweather.com/v5/weather?city=".$city."&&key=".$key;

 
/**
 取得天气数据集合
 */

        $weather            = json_decode(curl_https($url))->HeWeather5[0];


        $daily_forecast     = $weather->daily_forecast;

        $hourly_forecast    = $weather->hourly_forecast;

        $now                = $weather->now;

        $tmp                = $daily_forecast[0]->tmp;

        $aqi                = $weather->aqi;


/**
 黄历接口
 */
        $calkey             = '4cfa6cca596f9c48f04cccce3afc6b54';

        $today              = date("Y-m-d");

        $calurl             = "http://v.juhe.cn/laohuangli/d?date=".$today."&key=".$calkey;

        $calapi     = new \Common\Util\ResultApi();
        $caldata    = $api->getApiData($calurl, 'json');

        $cal        = $caldata->result;

/**
 打印测试区
 */

        // NSLog($caldata->result->yi);

        // $week = get_week($daily_forecast[0]->date);
        
        // echo "<pre>";
        // var_dump($daily_forecast[1]->tmp->max);

        // // // var_dump($hourly_forecast);
        // // var_dump($aqi);
        // echo "<pre/>";
          
        // var_dump($daily_forecast[1]->wind->dir);

/**
 分配变量
 */
        $this->assign('cal',$cal);

        $this->assign('now',$now);

        $this->assign('tmp',$tmp);

        $this->assign('aqi',$aqi);

        $this->assign('daily_forecast',$daily_forecast);

        $this->assign('weather',$weather);

        $this->display();


      }


}





